import java.util.Arrays;
import java.util.PriorityQueue;

public class GetSubject {

    public static int getcount(int[][] courses){

        Arrays.sort(courses,(a,b)->a[1]-b[1]);
        PriorityQueue<Integer> queue=new PriorityQueue<Integer>((a,b)->a-b);
        int total=0;
        for(int[] cour:courses){
            int a=cour[0];
            int b=cour[1];
            if(a+total<b){
                total+=a;
                queue.offer(a);
            }else if(!queue.isEmpty()&&queue.peek() > a){
                total -= queue.poll() - a;
                queue.offer(a);

            }
        }
        return queue.size();
    }

    public static void main(String[] args) {
        int[][] cour={{100,200},{200,1300},{1000,1250},{2000,3200}};
        getcount(cour);
    }
}
